package com.wuzf.mall.fragment

import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import me.yokeyword.fragmentation.SupportActivity
import me.yokeyword.fragmentation.SupportFragment
import me.yokeyword.fragmentation.SupportFragmentDelegate


abstract class BaseFragment : SupportFragment() {

    private lateinit var nRootView: View

    // 设置layout
    abstract fun setLayout(): Any

    // 绑定View
    abstract fun onBindView(savedInstanceState: Bundle?, rootView: View)

    // 查找View中的组件
    fun <T : View> findView(id: Int): T {
        return nRootView.findViewById(id)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val root = when {
            setLayout() is Int -> inflater.inflate(setLayout() as Int, container, false)
            setLayout() is View -> setLayout() as View
            else -> throw ClassCastException("must is Int or View")
        }
        nRootView = root
        onBindView(savedInstanceState, root)
        return root
    }
}